package serverService;

import java.util.*;
import java.util.logging.Logger;
import java.io.*;
import java.net.*;

public class StockExchangeServer {
	static Logger logger = Logger.getLogger(StockExchangeServer.class.getName());
	static Map<String, ClientSession> listOfClientSession = new HashMap<String, ClientSession>();
	static ServerSocket serverSocket;
	static Matcher matcherThread;

	public static void main(String[] args) {
		//startMatcher();
		startExchange();
	}

	public static void startExchange() {
		System.out.println("Waiting for connection...");
		do {
			try {
				serverSocket = new ServerSocket(5090);
				Socket clientSocket = serverSocket.accept();
				logger.info("Connection received from "
						+ clientSocket.getInetAddress().getHostName());
				ClientSession clientSession = new ClientSession(clientSocket);
				clientSession.start();

			} catch (UnknownHostException unknownHost) {
				logger.warning("You are trying to connect to an unknown host!");
			} catch (IOException ioException) {
				ioException.printStackTrace();
			} finally {
				try {
					serverSocket.close();
				} catch (IOException ioException) {
					ioException.printStackTrace();
				}
			}
		} while (true);
	}

	public static void startMatcher() {
		matcherThread = new Matcher();
	}
}
